<?php
// use the dPFramework to have easy database operations (store, delete etc.) by using its ObjectOrientedDesign
// therefore we have to create a child class for the module einstein

// a class named (like this) in the form: module/module.class.php is automatically loaded by the dPFramework

/**
 *	@package dotProject
 *	@subpackage modules
 *	@version $Revision: 1.0 $
*/

// include the powerful parent class that we want to extend for einstein
require_once( $AppUI->getSystemClass ('dp' ) );		// use the dPFramework for easy inclusion of this class here

/**
 * The Supplier Class
 */
class CTransportation extends CDpObject {
	// link variables to the einstein object (according to the existing columns in the database table einstein)
	var $trans_id = NULL;	//use NULL for a NEW object, so the database automatically assigns an unique id by 'NOT NULL'-functionality
	var $trans_code = NULL;
	var $trans_name = NULL;
	var $trans_status = NULL;
	var $trans_type = NULL;
	var $trans_division = NULL;
	var $trans_costcenter = NULL;
	var $trans_resource = NULL;
	var $trans_active = 1;

	// the constructor of the CEinstein class, always combined with the table name and the unique key of the table
	function CTransportation() {
		$joins = array(
			array('label'=>'Task log',name=>'task_log_transportations', 'idfield'=>'tlog_task_log', 'joinfield'=>'tlog_transportation'),
		);
		$this->CDpObject( 'transportations', 'trans_id', 'trans_code', $joins, 'masterdata' );
	}

	function check() {
		if (!isset($this->_tbl_unique) || $this->_tbl_unique == NULL) {
			return NULL;
		}
		$q = new DBQuery();
		$q->addTable("$this->_tbl");
		$q->addWhere("$this->_tbl_key != $this->trans_id");
		$q->addWhere("$this->_tbl_unique = '$this->trans_code'");
		$result = $q->loadResult();
		if (isset($result) && $result != '') {
			return 'Duplicate transportation code: ' . $this->trans_code;
		}
		return NULL;
	}

	function getStatusName(){
		//$sql = "select status_name from md_status where status_id = '" . $this->unit_status . "'";
		$q  = new DBQuery;
		$q->addTable('md_status');
		$q->addQuery('status_name');
		$q->addWhere('status_id = '.$this->trans_status);
		$sql = $q->prepare();
		$q->clear();
		$status_name = db_loadResult( $sql );
		return $status_name;
 	}

 	function getTypeName(){
		//$sql = "select status_name from md_status where status_id = '" . $this->unit_status . "'";
		$q  = new DBQuery;
		$q->addTable('md_type');
		$q->addQuery('name');
		$q->addWhere('type_id = '.$this->trans_type);
		$sql = $q->prepare();
		$q->clear();
		$type_name = db_loadResult( $sql );
		return $type_name;
 	}
 	function getCostCenterName(){
 		if($this->trans_costcenter!=null){
			$q  = new DBQuery;
			$q->addTable('costcenters');
			$q->addQuery('cc_name');
			$q->addWhere('cc_id = '.$this->trans_costcenter);
			$sql = $q->prepare();
			$cc_name = db_loadResult( $sql );
			return $cc_name;
 		}
 	}
}
function getTransportationList(){
	$q  = new DBQuery;
	$q->addTable('transportations');
	$q->addQuery('trans_id, trans_name');
	$q->addQuery('trans_active = 1');
	$sql = $q->prepare();
	$q->clear();
	return db_loadHashList($sql);
}

?>